package com.lin.web;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.jxls.reader.ReaderBuilder;
import net.sf.jxls.reader.XLSReader;

public class Util<T> {
	
	public List<T> parseExcelFileToBeans(File xlsFile, File jxlsConfigFile)
			throws Exception {
		XLSReader xlsReader = ReaderBuilder.buildFromXML(jxlsConfigFile);
		List<T> result = new ArrayList<T>();
		Map<String, Object> beans = new HashMap<String, Object>();
		beans.put("result", result);
		InputStream inputStream = null;
		try {
			inputStream = new BufferedInputStream(new FileInputStream(xlsFile));
			xlsReader.read(inputStream, beans);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (inputStream != null) {
				inputStream.close();
			}
		}
		return result;
	}
}
